package infoexract.exractreason.samesent.treepattern.pattern;

import infoexract.exractreason.samesent.treepattern.ExtractReasonOneSentTreePattern;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

import org.w3c.dom.Node;

public class SynTaxTreePatternSet {
	private Vector<SynTaxTreePattern> patternVector = new Vector<SynTaxTreePattern>();
	public void ReadFromPatternFile(String filename)
	{
		try {
			BufferedReader freader = new BufferedReader(new FileReader(filename));
			String line;
			while((line=freader.readLine())!=null)
			{
				if(line.length()>0) 
				{
					SynTaxTreePattern pattern = new SynTaxTreePattern();
					pattern.ReadPatternLine(line);
					this.patternVector.add(pattern);
				}
			}
			freader.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public boolean isMatch(Node[] entityNodeParents, int entitySameIndex, Node[] attributeNodeParents, int attributeSameIndex)
	{
		for(int i=0;i<this.patternVector.size();i++)
		{
			SynTaxTreePattern pattern = this.patternVector.elementAt(i);
			boolean ismatch = pattern.isMatch(entityNodeParents, entitySameIndex, attributeNodeParents, attributeSameIndex);
			
			if(ismatch) ExtractReasonOneSentTreePattern.patternNums+=i+1;
			
			if(ismatch) return true;
		}
		return false;
	}
}
